package com.crrc.dataparse.monitor.rsp.service.parse.treat.templatepara.datatrans;

import com.crrc.dataparse.templatepara.IDataTrans;

/*
     2进制转字符串
 */
public class BinaryToString extends IDataTrans {
    public BinaryToString() {
    }

//    @Override
//    public String trans(String value, double resolusion, double offset) throws Exception {
//        String result = "";
//// TODO: 2023/12/27/027 此处需根据实际情况看是否需要每8位进行拆分
//        for (int i = 0; i < value.length(); i = i + 8) {
//            String s = value.substring(i, i + 8);
//            long ss = Long.valueOf(s, 2);
//            String s1 = Long.toString(ss);
//            result = result + s1.toUpperCase();
//        }
//        return result;
//    }

    //临时针对性解决方法(使得列车号小于10的为01、02。。。;大于等于10的为原数)
    @Override
    public String trans(String value, double resolusion, double offset) throws Exception {
        long ss = Long.valueOf(value, 2);
        String result;
        if (ss > 9) {
            result = Long.toString(ss);
        }else {
            result = "0"+Long.toString(ss);
        }
        return result;
    }
}